<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/message.css"/>
    <link rel="stylesheet" href="/css/like.css"/>
    <link rel="stylesheet" href="../js/plugins/jquery-confirm/css/jquery-confirm.css">
    <script src="../js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
    <script src="../js/plugins/jrender/jrender.min.js"></script>
    <script src="../js/plugins/dialog2/dialog.min.js"></script>
    <link rel="stylesheet" href="../js/plugins/dialog2/dialog.css">

</head>
<script>
    $(function () {

        var users = sessionStorage.getItem("user");
        var user = JSON.parse(users);

        function query(){$.get("/users/" + user.id + "/letters/content", {pageSize: 0}, function (data) {
            $(".detail").renderValues(data, {
                    'setHref': function (item, value) {
                        $(item).attr("href", $(item).attr("href") + value);

                    }
                }
            );
            currentPage += 1;
            totalPage = data.pages;
            $(".ibtn").click(function () {
                var id = $(this).data("id");
                $.confirm({
                    title: '私信内容',
                    content: '' +
                    '<form action="" class="formName">' +
                    '<div class="form-group">' +
                    '<label>请在这里输入您的私信内容(不得大于15字符)</label>' +
                    '<input type="text" placeholder="请输入私信内容" class="name form-control" required maxlength="15"/>' +
                    '</div>' +
                    '</form>',
                    buttons: {
                        formSubmit: {
                            text: '确认',
                            btnClass: 'btn-blue',
                            action: function () {
                                var name = this.$content.find('.name').val();
                                if (!name) {
                                    $.alert('至少输入一个字段');
                                    return false;
                                }
                                $.get("/users/" + user.id + "/" + id + "/" + name + "/letters", function (data) {
                                    if (data.success) {
                                        window.location.reload();
                                    } else {
                                        $.alert(data.msg);
                                    }
                                })
                            }
                        },
                        关闭: function () {
                        }
                    },
                    onContentReady: function () {
                        var jc = this;
                        this.$content.find('form').on('submit', function (e) {
                            e.preventDefault();
                            jc.$$formSubmit.trigger('click');
                        });
                    }
                });
            });

        });}

        query();
        var currentPage;
        var dataList = [];
        var totalPage = 1;
        $(window).scroll(function () {
            if ($(window).height() + $(window).scrollTop() >= $(document).height()) {
                if (currentPage <= totalPage) {
                    query();
                } else {
                    $(document).dialog({
                        type: 'notice',
                        infoText: '到底了',
                        autoClose: 1500,
                        position: 'bottom'
                    })
                }
            }
        });
    });

</script>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>私信查看</span>
        </div>
        <div class="col"></div>
    </div>
</div>
<div class="container">
    <h3 style="color: aquamarine">私信列表:</h3>
    <div class="row detail">
        <div class="col" render-loop="list">
            <div>
                <a href="../userProfiles.html?id=" render-fun="setHref" render-key="list.messages.id">
                    <img render-src="list.messages.headImgUrl" class="rounded-circle head-img"/>
                    <span render-html="list.messages.nickName" style="color: blueviolet"></span> </a>在
                <p/>
                <span render-html="list.messagesDate" style="color: chartreuse"></span>
                对您发来
                <p/>
                <div class="focus">
                    <i class="fa fa-envelope-o">
                        <span render-html="list.content" style="color: crimson"></span>
                    </i>
                </div>
                <div class="col">
                    <button class="btn btn-info ibtn" type="button" render-attr="data-id=list.messages.id">回复私信
                    </button>
                </div>
                <hr/>
            </div>

        </div>

    </div>
</div>
</body>
</html>